<template>
  <el-dialog
    title="发布记录"
    :visible.sync="open"
    width="600px"
    append-to-body
    @close="closeDialog"
    class="business-dialog"
    :close-on-click-modal="false"
  >
    <el-timeline>
      <el-timeline-item
        timestamp=""
        v-for="item of timelineData"
        :key="item.id"
      >
        <p>{{ item.taskStatusName }} {{ item.recordTime }}</p>
        <p v-if="item.taskStatus === 7">
          失败原因：{{ item.taskFailMsg }}
          <el-button type="text" size="mini" @click="retryPublish"
            >重试</el-button
          >
        </p>
      </el-timeline-item>
    </el-timeline>
  </el-dialog>
</template>
<script>
import { Message } from "element-ui";
import { publishDoc, getPublishRecordList } from "@/api/business";

export default {
  name: "DocPublishHistoryModal",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    docNo: {
      type: String,
      default: "",
    },
  },
  watch: {
    async visible(val) {
      this.open = val;
      if (val) {
        this.getList();
      } else {
        this.timelineData = [];
      }
    },
  },
  data() {
    return {
      open: this.visible,
      timelineData: [],
    };
  },
  methods: {
    async getList() {
      const res = await getPublishRecordList(this.docNo);
      this.timelineData = res.data;
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
    async retryPublish() {
      try {
        await MessageBox.confirm(`此操作将发布文件，是否继续？`, '提示', {
          type: 'warning'
        })
        await publishDoc({ docNo: this.docNo });
        Message.success("发布成功");
        this.getList();
      } catch (error) {
        console.debug(error);
      }
    },
  },
};
</script>
<style scoped>
p {
  margin: 0;
}
</style>
